<?php

namespace Forum\ForumBundle\Form;

use Symfony\Component\Form\Form;
use Symfony\Component\Form\TextareaField;

use Forum\ForumBundle\Entity\Topic;
use Forum\ForumBundle\Entity\Message;


class ReplyForm extends Form {

    /**
     * $validation:NotBlank
     */
    public $message;

    public function configure(){

        $this->add(new TextareaField('message'));

    }

    public function save($em, $id){

        $message = new Message();
        $message->setContenu_message($this->message);

        // auteur du message
        $membre = $em->getRepository('Blog\AccBundle\Entity\Membre')->findOneBy(array('id_membre' => 1));

        $topic = $em->getRepository('Forum\ForumBundle\Entity\Topic')->findOneBy(array('id_topic' => $id));

        $message->setTopic($topic);
        $message->setMembre($membre);
        $message->setDate_message(\date_create(date('Y-m-d H:i:s')));

        $em->persist($message);
        $em->flush();


    }


}
?>
